#pragma once
#include "vn/NetworkStream.h"

#include "vn/TcpClient.h"
#include "vn/FileStream.h"

void Copy(Stream &des, Stream &src) {
	CHECK_ARG(des.CanWrite());
	CHECK_ARG(src.CanRead());
	Buf8 buf[500];
	while(true) {
		StmLen nRead = src.Read(buf, 5);
		if(nRead == 0)
			break;
		des.Write(buf, nRead);
	}
}

void NetworkStreamTest() {_test_func_;
	{
		Socket *psock = new Socket;
		psock->OpenTcp();
		psock->Connect("localhost", 8443);

		NetworkStream a;
		IO::FileStream out;
		a.Attach(psock, true);
		Buf8 *request = "GET /index.html /HTTP/1.1\r\n\r\n\r\n";
		a.Write(request, strlen(request));
		out.Open("c:\\out.html", IO::FileMode::Create);
		Copy(out, a);
	}

	{
		NetworkStream a;
		Socket s;
		s.OpenTcp();
		s.Connect("localhost", 8443);
		a.Attach(&s);
	}


	{
		TcpClient tcpClient;
		tcpClient.Connect("localhost", 8443);
		NetworkStream a;
		tcpClient.GetStream(a);
	}
}
